public class Reverse {
    public static MySingleList.ListNode reverseList(MySingleList.ListNode head) {
        //处理特殊情况，如果单链表为空或者只有一个结点
        if(head == null || head.next == null) {
            return head;
        }

        //利用头插法逆置单链表
        MySingleList.ListNode cur = head.next;
        head.next = null;
        while(cur != null) {
            MySingleList.ListNode curN = cur.next;
            //执行头插法
            cur.next = head;
            head = cur;
            cur = curN;
        }

        return head;
    }

    public static MySingleList.ListNode reverse(MySingleList.ListNode head) {
        if(head == null || head.next == null) {
            return head;
        }

      MySingleList.ListNode newHead =  reverse(head.next);

        head.next.next = head;
        head.next = null;
        return newHead;
    }
    public static void main(String[] args) {
        MySingleList singleList = new MySingleList();
        singleList.addLast(1);
        singleList.addLast(2);
        singleList.addLast(3);

        singleList.disPlay(singleList.head);

        singleList.head = reverse(singleList.head);

        singleList.disPlay(singleList.head);
    }
}
